package com.ly.wxPay.service;

import com.ly.common.core.bean.R;
import com.ly.wxPay.bean.dto.OrderRefundsDTO;
import com.ly.wxPay.bean.dto.WxOrderDTO;
import com.ly.wxPay.bean.vo.OrderVO;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 支付-服务
 *
 * @author luoyun
 * @Date: 2025-11-22
 */
public interface IWxService {
    /**
     * 创建订单
     */
    R nativePay(WxOrderDTO dto);

    /**
     * 微信回调-订单后续操作
     */
    void processOrder(Map<String, Object> map);

    /**
     * 微信回调-退款单后续操作
     */
    void processRefund(Map<String, Object> map);

    /**
     * 关闭订单
     */
    R cancelOrder(String orderId);

    /**
     * 查询订单-wx
     *
     * @desc: 返回参数示例
     * {
     * "amount": {
     * "currency": "CNY",
     * "payer_currency": "CNY",
     * "payer_total": 1,
     * "total": 1
     * },
     * "appid": "wx74862e0dfcf69954",
     * "attach": "",
     * "bank_type": "OTHERS",
     * "mchid": "1558950191",
     * "out_trade_no": "ORDER_20251122194842729",
     * "payer": {
     * "openid": "oHwsHuMpxTArU3I0vfB-unM9eyys"
     * },
     * "promotion_detail": [
     * <p>
     * ],
     * "success_time": "2025-11-22T19:49:18+08:00",
     * "trade_state": "SUCCESS",
     * "trade_state_desc": "支付成功",
     * "trade_type": "NATIVE",
     * "transaction_id": "4200002878202511227719917780"
     * }
     */
    R<OrderVO> getOrder(String no);

    /**
     * 查询退款
     */
    R<OrderVO> getRefundOrder(String no);

    /**
     * 订单退款
     *
     * @desc: 返回参数示例
     * {
     * "amount": {
     * "currency": "CNY",
     * "discount_refund": 0,
     * "from": [
     * <p>
     * ],
     * "payer_refund": 1,
     * "payer_total": 1,
     * "refund": 1,
     * "refund_fee": 0,
     * "settlement_refund": 1,
     * "settlement_total": 1,
     * "total": 1
     * },
     * "channel": "ORIGINAL",
     * "create_time": "2025-11-23T13:39:36+08:00",
     * "funds_account": "UNAVAILABLE",
     * "out_refund_no": "REFUND_20251123133937540",
     * "out_trade_no": "ORDER_20251121161548255",
     * "promotion_detail": [
     * <p>
     * ],
     * "refund_id": "50303005392025112347024967966",
     * "status": "PROCESSING",
     * "transaction_id": "4200002955202511215474848910",
     * "user_received_account": "支付用户零钱"
     * }
     */
    R refundOrder(OrderRefundsDTO dto);

    /**
     * 核实订单状态
     * 已支付则记录支付日志并更新订单状态；未支付则关闭订单并更新订单状态
     */
    void checkOrderStatus(String orderNo) throws Exception;

    void checkRefundStatus(String refundNo) throws Exception;

    /**
     * 查询账单
     *
     * @param billDate：账单日期
     * @param type：账单类型
     * @return
     * @desc: https://api.mch.weixin.qq.com/v3/billdownload/file?token=XJDGh7Mct3OXCpiusKnOXWIZiCPlKZLphJbaM0d7_DrewrGiRbWnm1ZXSeaYF2sA
     */
    String queryBill(String billDate, String type);

    /**
     * 下载账单
     *
     * @param billDate
     * @param type
     */
    R downloadBill(String billDate, String type);

    /**
     * 确定订单
     */
    R confirmOrder(Long id);

    /**
     * 支付成功回调通知
     *
     * @param request
     * @param response
     * @return
     */
    String nativeNotify(HttpServletRequest request, HttpServletResponse response);

    /**
     * 退款成功回调通知
     *
     * @param request
     * @param response
     * @return
     */
    String refundsNotify(HttpServletRequest request, HttpServletResponse response);

    /**
     * v2支付
     * @param dto
     * @return
     * @throws Exception
     */
    Map<String, Object> nativePayV2(WxOrderDTO dto) throws Exception ;
}
